package com.shitou.shitouproduct.controller;


import com.shitou.shitoucommons.utils.PageUtils;
import com.shitou.shitoucommons.utils.RespBean;
import com.shitou.shitouproduct.entity.CarouselEntity;
import com.shitou.shitouproduct.entity.HotSpuEntity;
import com.shitou.shitouproduct.service.CarouselService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.Date;
import java.util.Map;

/**
 * 属性分组
 *
 * @author 石头人
 * @email 3076767823@qq.com
 * @date 2023-03-04 18:03:45
 */
@RestController
@RequestMapping("shitouproduct/carousel")
public class CarouselController {

    @Resource
    private CarouselService carouselService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    public RespBean list(@RequestParam Map<String, Object> params){
        PageUtils page = carouselService.queryPage(params);

        return RespBean.success().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public RespBean info(@PathVariable("id") Long id){
        CarouselEntity carousel = carouselService.getById(id);

        return RespBean.success().put("carousel", carousel);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public RespBean save(@RequestBody CarouselEntity carousel){
        carouselService.save(carousel);

        return RespBean.success();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public RespBean update(@RequestBody CarouselEntity carousel){
        carouselService.updateById(carousel);

        return RespBean.success();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public RespBean delete(@RequestBody Long[] ids){
        carouselService.removeByIds(Arrays.asList(ids));

        return RespBean.success();
    }


    /**
     * 获得展示商品
     * @return
     */
    @GetMapping("/getShow")
    public RespBean getShow(){
        return carouselService.getShow();
    }


    /**
     * 更新状态
     * @param id
     * @param status
     * @return
     */
    @PostMapping("/updateStatus")
    public RespBean updateStatus(@RequestParam Long id, @RequestParam Integer status){
        CarouselEntity carousel = new CarouselEntity();
        carousel.setId(id);
        carousel.setStatus(status);
        carousel.setUpdateTime(new Date());
        boolean b = carouselService.updateById(carousel);
        return b?RespBean.success():RespBean.error("更新状态失败");
    }
}




